package cn.sykj.car.utils;

import org.apache.commons.lang3.RandomStringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class BusinessUtils {
    public static final String ORDER_NO_PREFIX = "11";
    public static final String WITHDRAW_NO_PREFIX = "12";
    public static final String SERVICE_NO_PREFIX = "21";
    public static final String RECHARGE_NO_PREFIX = "22";
    public static final String COMMISSION_NO_PREFIX = "23";
    public static final String ACHIEVEMENT_NO_PREFIX = "24";
    public static final String REFUND_NO_PREFIX = "25";
    public static final String BEAN_ADD_NO_PREFIX = "31";
    public static final String BEAN_SUB_NO_PREFIX = "32";
    public static final String PLUS_ORDER_NO_PREFIX = "41";
    public static final String COUPON_PREFIX = "A";
    public static final String FREIGHT_COUPON_PREFIX = "B";
    public static final String CERT_NO_PREFIX = "CR";

    public static String generatorCertNo() throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(6,false,true);
        return CERT_NO_PREFIX + dateStr + random;
    }

    public static String generatorOrderNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return ORDER_NO_PREFIX + dateStr + random;
    }
    public static String generatorRefundNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return REFUND_NO_PREFIX + dateStr + random;
    }
    public static String generatorPlusOrderNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return PLUS_ORDER_NO_PREFIX + dateStr + random;
    }
    public static String generatorRechargeNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return RECHARGE_NO_PREFIX + dateStr + random;
    }
    public static String generatorServiceNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return SERVICE_NO_PREFIX + dateStr + random;
    }
    public static String generatorWithdrawNo(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssSSS");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return WITHDRAW_NO_PREFIX + dateStr + random;
    }

    public static String generatorVerifyCode(){
        String random = RandomStringUtils.random(6,false,true);
        return random;
    }
    public static String generatorDiscountCouponNo(){
        int len = 24;
        char c[] = "ABCDEFGHJKLMNPQRSTUVWXYZ1234567890".toCharArray();
        String random = RandomStringUtils.random(len, c);
        return COUPON_PREFIX + random;
    }
    public static String generatorFreightCouponNo(){
        int len = 24;
        char c[] = "ABCDEFGHJKLMNPQRSTUVWXYZ1234567890".toCharArray();
        String random = RandomStringUtils.random(len, c);
        return FREIGHT_COUPON_PREFIX + random;
    }
    public static String generatorAgentCode(){
        int len = 8;
        char c[] = "ABCDEFGHJKLMNPQRSTUVWXYZ1234567890".toCharArray();
        String random = RandomStringUtils.random(len, c);
        return FREIGHT_COUPON_PREFIX + random;
    }
    public static void main(String[] args) {
        System.out.println(generatorDiscountCouponNo());
        System.out.println(generatorFreightCouponNo());
    }

    public static String generatorUserCode(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        String dateStr = sdf.format(new Date());
        String random = RandomStringUtils.random(3,false,true);
        return  dateStr + random;
    }
}
